package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.mapper.LeaseAgreementMapper;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Override
    public void updateStatusById(Long id, LeaseStatus status) {
        //根据id更新status
        LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper
                .eq(LeaseAgreement::getId, id)
                .set(LeaseAgreement::getStatus, status);
        this.update(updateWrapper);
    }

    //这里使用了多表关联查询，为了效率，可以在service层查询，减少数据库多表关联查询，提高效率
    @Override
    public IPage<AgreementVo> pageLeaseAgreementByQuery(long current, long size, AgreementQueryVo queryVo) {
        Page<AgreementVo> page = new Page<>(current, size);
        return baseMapper.pageLeaseAgreementByQuery(page, queryVo);
    }

    @Override
    public AgreementVo getAgreementById(Long id) {
        return baseMapper.getLeaseAgreementById(id);
    }

}




